package com.swanclouds.redfish.event.domain;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.swanclouds.model.event.Subscriptions;
import com.swanclouds.redfish.common.redfish.MemberModel;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 李文强
 * description 订阅服务实体类
 */
public class SubscriptionsModel implements Subscriptions {

    /**
     * 事件订阅资源模型的OData描述信息
     */
    @JsonProperty("@odata.context")
    private String odataContext;

     /**
     *事件订阅集合资源模型的电子标签
     */
     @JsonProperty("@odata.etag")
     private String etag;

    /**
     *事件订阅资源节点的访问路径
     */
    @JsonProperty("@odata.id")
    private String dataId;

    /**
     * 事件订阅资源类型
     */
    @JsonProperty("@odata.type")
    private String type;

    /**
     * 目的地事件服务的URI
     */
    @JsonProperty("Description")
    private String description;

    /**
     * 事件订阅集合资源数量
     */
    @JsonProperty("Members@odata.count")
    private Integer membersCount;

    @JsonProperty("Members")
    private List<MemberModel> members;

    /**
     * 系统集合成员列表
     *
     * @return java.util.List
     */
    @Override
    public List<String> getCollectionResourceList() {
        List<String> collectionResourceList = new ArrayList<>();
        if (this.members != null && this.members.size() > 0) {
            this.members.stream().forEach(member -> {
                collectionResourceList.add(member.getDataId());
            });
        }
        return collectionResourceList;
    }

    /**
     * 客户端提供的与事件目标
     * 订阅一起存储的字符串
     */
    @JsonProperty("Context")
    private String context;

    /**
     * 包含将要发送到指定的事
     * 件的类型
     */
    @JsonProperty("EventTypes")
    private List<String> eventTypes;

    /**
     * 事件订阅HTTP头，查询时
     * 对外显示为null
     */
    @JsonProperty("HttpHeaders")
    private String httpHeaders;

    /**
     * 事件订阅资源的ID
     */
    @JsonProperty("Id")
    private String id;

    /**
     * 事件消息Id匹配列表
     */
    @JsonProperty("MessageIds")
    private List<String> messageIds;

    /**
     * 事件源匹配列表
     */
    @JsonProperty("OriginResources")
    private List<String> originResources;

    /**
     * 客户端提供的与事件目标
     * 订阅一起存储的字符串
     */
    @JsonProperty("OriginResources@odata.count")
    private String count;

    /**
     * 事件连接的协议类型
     * Redfish
     */
    @JsonProperty("Protocol")
    private String protocol;

    /**
     *
     */
    @JsonProperty("SubscriptionType")
    private String subscriptionType;

    /**
     * 事件订阅资源的名称
     */
    @JsonProperty("Name")
    private String name;

    @Override
    public String getDataId() {
        return this.dataId;
    }

    @Override
    public String getContext() {
        return this.context;
    }

    @Override
    public String getType() {
        return this.type;
    }

    @Override
    public String getId() {
        return this.id;
    }

    @Override
    public String getName() {
        return this.name;
    }

    public String getOdataContext() {
        return odataContext;
    }

    public String getEtag() {
        return etag;
    }

    public String getDescription() {
        return description;
    }

    public List<String> getEventTypes() {
        return eventTypes;
    }

    public String getHttpHeaders() {
        return httpHeaders;
    }

    public List<String> getMessageIds() {
        return messageIds;
    }

    public List<String> getOriginResources() {
        return originResources;
    }

    public String getCount() {
        return count;
    }

    public String getProtocol() {
        return protocol;
    }

    public String getSubscriptionType() {
        return subscriptionType;
    }

    @Override
    public Integer getMembersCount() {
        return membersCount;
    }

    public List<MemberModel> getMembers() {
        return members;
    }

    @Override
    public String toString() {
        ObjectMapper objectMapper = new ObjectMapper();
        try {
            return objectMapper.writeValueAsString(this);
        } catch (JsonProcessingException e) {
        }
        return "SubscriptionsModel{" +
                "@odata.context='" + odataContext + '\'' +
                ", @odata.etag='" + etag + '\'' +
                ", @odata.id='" + dataId + '\'' +
                ", @odata.type='" + type + '\'' +
                ", Context='" + context + '\'' +
                ", Destination='" + description + '\'' +
                ", EventTypes='" + eventTypes + '\'' +
                ", HttpHeaders='" + httpHeaders + '\'' +
                ", Id='" + id + '\'' +
                ", MessageIds='" + messageIds + '\'' +
                ", OriginResources='" + originResources + '\'' +
                ", OriginResources@odata.count='" + count + '\'' +
                ", Protocol='" + protocol + '\'' +
                ", SubscriptionType='" + subscriptionType + '\'' +
                ", name='" + name + '\'' +
                '}';
    }
}
